<template>
    <van-pull-refresh
        v-model="isLoading" 
        @refresh="onRefresh"
        success-text="刷新成功"
        :head-height="120"
    >
        <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多数据了"
            @load="onLoad"
            :immediate-check="false"
        >
            <slot></slot>
        </van-list>
    </van-pull-refresh>
</template>


<script>
export default {
    data(){
        return {
            isLoading:false,
            loading:false,
            finished:false, // 数据是否见底 
        }
    },
    props:['loadmoredata'],
    methods:{
        onLoad(){  // 上拉加载更多
            this.loadmoredata(()=>{
                this.loading = false;  
            },()=>{
                this.finished = true;  
            })
        },
        onRefresh(){   // 下拉刷新
            setTimeout(() => {
                this.$toast('刷新成功');
                this.isLoading = false;
                this.$emit('refresh')
            }, 1000);
        }
    }
}
</script>